<?php
    header('Content-type: text/html; charset=utf-8');
    error_reporting(E_ALL); 
    date_default_timezone_set("Asia/Saigon");
    require_once("config.php");     
    require_once("functions.php");     
    
    $data = getUserIdByRefCode("179129d77210df12c59d7a9d867324");
    $password = "2b97aa29636e35c80e95cb04427df9e9";
    $lid = getMaxTransIdViVoo();
    if(empty($lid)) {
        $lid=1;
    }
    $url = "http://id.vivoo.vn/card_report2.php?pass=".$password."&lid=".$lid;
    $json=cUrl($url);
    //echo $json ;die;
    //$json ='{"code":1,"trans_list":[{"trans_id":"915240","game":"Vua Bai","card_provider":"Mobifone","card_seri":"185982498974","card_pin":"020971001137041","card_price":"20000","refcode":"1577","date_time":"1389242469"},{"trans_id":"915245","game":"Vua Bai","card_provider":"Mobifone","card_seri":"650708519597","card_pin":"020971001137040","card_price":"20000","refcode":"1577","date_time":"1389242734"},{"trans_id":"915745","game":"Than Nong","card_provider":"Vinaphone","card_seri":"91395449756876","card_pin":"anz294467","card_price":"20000","refcode":"1577","date_time":"1389340068"},{"trans_id":"915780","game":"PI","card_provider":"Vinaphone","card_seri":"39017433443443","card_pin":"anz294464","card_price":"20000","refcode":"1577","date_time":"1389346675"}]}'; 
    //$json ='{"code":1,"trans_list":[{"trans_id":"915780","game":"PI","card_provider":"Vinaphone","card_seri":"39017433443443","card_pin":"anz294464","card_price":"20000","refcode":"179129d77210df12c59d7a9d867324","date_time":"1389346675"}]}';
    $arr =json_decode($json,true) ;
    if($arr['code']==1){
        $trans_list = $arr['trans_list'];
        $arr_values = array();
        $arr_key = array("transactionId","userId","partnerId","type","appID","provider_code","card_code","card_seri","price","charg_status","status","requested_date","responsed_date","day","month","year","create_date","percent_wapmaster","percent_partner");
        foreach( $trans_list as $value){
            if($value['card_provider']=="Mobifone"){
                 $provider_code ="VMS";
            }else if($value['card_provider']=="Vinaphone"){
                  $provider_code ="VNP"; 
            }else if($value['card_provider']=="Viettel") {
                  $provider_code = "VTT";
            }
            if($value['game']=="Than Nong"){
                 $appID =18;
            }else if($value['game']=="PI"){
                  $appID =6; 
            }else if($value['game']=="Vua Bai"){
                  $appID =11; 
            }
            $day = intval(date('d',$value['date_time']));
            $month = intval(date('m',$value['date_time']));
            $year = intval(date('Y',$value['date_time']));
            
            
            $gameInfo = getGameInfo($appID);     
            
            $arr_values[]=array($value['trans_id'],$value['refcode'],"60","1",$appID,$provider_code,$value['card_pin'],$value['card_seri'],$value['card_price'],2,1,$value['date_time'],$value['date_time'],$day,$month,$year,time(),$gameInfo['percent_wapmaster'],$gameInfo['percent_partner']);  
        }
         $result = insertManyRows("c_card_log",$arr_key,$arr_values) ;
         if ($result > 0){
                echo "Cron Job success at ".date("Y-m-d",time());
         }
    }else{
        echo "Chưa có dữ liệu mới";
    }
    
?>
